import moment from "moment";

export default function getWeekDays(date) {
  const givenDate = new Date(date);
  givenDate.setHours(0, 0, 0, 0); // 避免时间部分影响日期计算

  // 修正周一计算逻辑
  const dayOfWeek = givenDate.getDay();
  const startOfWeek = new Date(givenDate);
  const diff = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 处理周日的情况
  startOfWeek.setDate(givenDate.getDate() - diff);

  const weekDays = [];
  for (let i = 0; i < 7; i++) {
    const currentDay = new Date(startOfWeek);
    currentDay.setDate(startOfWeek.getDate() + i);
    weekDays.push(moment(currentDay).format('yyyy-MM-DD'));
  }

  return weekDays;
}
